<template>
  <TableView
    ref="tableView"
    :table-attrs="{
      api: fetchList,
      descs: ['create_time'],
      dicOptions: [
        { prop: 'status', dicType: 'purchaseapply_status' },
        { prop: 'method', dicType: 'purchase_way' },
        { prop: 'currencyType', dicType: 'currency_type' },
        { prop: 'type', dicType: 'type_document' }
      ]
    }"
    form-path="/asset/purchaseApply/purchaseApplyForm/{id:-1}"
    :search-model="searchForm"
    :delete-api="batchDelete"
    :toolbar-attrs="{
      buttons: [
        'slot',
        {
          del: 'purchaseApply_fyassetpurchaseapply_del',
          create: 'purchaseApply_fyassetpurchaseapply_add'
        }
      ]
    }">
    <template #toolbar-button="{ selectedRows }">
      <ToolbarButton privilege="purchaseApply_fyassetpurchaseapply_export" type="primary" icon="el-icon-download" label="导出" @click="exportExcel()" />
      <ToolbarButton icon="el-icon-printer" type="primary" label="打印" :disabled="selectedRows.length !== 1" @click="assetPrint(selectedRows)" />
    </template>
    <template #columns>
      <TableColumn label="单据类型" prop="type" width="80" />
      <TableColumn label="状态" prop="status" dict-type="asset_status" test="test" width="60" />
      <TableColumn label="采购单位" prop="purchaseOuname" width="160" />
      <TableColumn label="申请单号" clickable prop="caseid" width="125" />
      <TableColumn label="申请时间" prop="createTime" width="90">
        <template #default="{ row }">
          {{ $formatDate(row.createTime) }}
        </template>
      </TableColumn>
      <TableColumn label="申请人" prop="createBy" width="80" />
      <TableColumn label="预算编号" prop="budgetNumber" width="80" />
      <TableColumn label="预算名称" prop="budgetName" width="95" />
      <TableColumn label="供应商名称" prop="supplierName" width="100" />
      <TableColumn label="到货时间" prop="arrivalDatetime" width="90">
        <template #default="{ row }">
          {{ $formatDate(row.arrivalDatetime) }}
        </template>
      </TableColumn>
      <TableColumn label="采购方式" prop="method" width="80" />
      <TableColumn label="购置价格" prop="amount" width="80" />
      <TableColumn label="货币类型" prop="currencyType" width="80" />
      <TableColumn label="申请说明" prop="explains" />
      <TableColumn label="采购明细" prop="detailed" />
    </template>
    <template #search-form>
      <FormSelect v-model="searchForm.type" dict-type="type_document" label="单据类型" prop="type" />
      <FormSelect v-model="searchForm.status" dict-type="purchaseapply_status" label="状态" prop="status" />
      <FormInput v-model="searchForm.purchaseOuname" label="采购单位" prop="purchaseOuname" />
      <FormInput v-model="searchForm.caseid" label="申请单号" prop="caseid" />
      <FormDatePicker v-model="searchForm.createTime" label="申请时间" :split="false" date-range prop="createTime" />
      <FormDatePicker v-model="searchForm.arrivalDatetime" label="到货时间" :split="false" date-range prop="arrivalDatetime" />
      <FormInput v-model="searchForm.createBy" label="申请人" prop="createBy" />
      <FormInput v-model="searchForm.deptFullname" label="申请单位" prop="deptFullname" />
      <FormInput v-model="searchForm.budgetNumber" label="预算编号" prop="budgetNumber" />
      <FormInput v-model="searchForm.budgetName" label="预算名称" prop="budgetName" />
      <FormInput v-model="searchForm.supplierName" label="供应商" prop="supplierName" />
      <FormInput v-model="searchForm.detailed" label="采购明细" prop="detailed" />
      <FormSelect v-model="searchForm.method" dict-type="asset_purchase_method" label="采购方式" prop="method" />
    </template>
  </TableView>
</template>

<script>
  import { services } from '@/config'
  import { fetchList, batchDelete } from '@/api/asset/fyassetpurchaseapply'
  import { printReport } from '@/util/print'
  import { downBlobFile } from '@/util'

  export default {
    name: 'PurchaseApplyView',
    data() {
      return {
        searchForm: {
          type: '',
          purchaseOuname: '',
          caseid: '',
          createTime: [],
          arrivalDatetime: [],
          createBy: '',
          deptFullname: '',
          budgetNumber: '',
          budgetName: '',
          supplierName: '',
          method: '',
          detailed: '',
          status: ''
        }
      }
    },
    methods: {
      fetchList,
      batchDelete,
      assetPrint(selectedRows) {
        printReport(selectedRows[0], '请选择申请信息！', 'oss_pruchaseapply.ureport.xml')
      },
      exportExcel() {
        downBlobFile(`${services.assetService}fyassetpurchaseapply/export`, this.searchForm, '采购申请导出信息.xlsx')
      }
    }
  }
</script>
